#include "Com_Util.h"

void Com_Util_Delay_500ms(void)
{
    for (uint16_t i = 0; i < 250; i++)
    {
        for (uint16_t n = 0; n < 300; n++)
        {
            for (uint16_t m = 0; m < 60; m++)
            {
                
            }
            
        }
        
    }
    
}

void Delay_us(uint32_t us)
{
    SysTick->CTRL |= SysTick_CTRL_CLKSOURCE;
    SysTick->CTRL &= ~SysTick_CTRL_TICKINT;
    SysTick->LOAD = 72 * us;
    SysTick->VAL = 0;
    
    SysTick->CTRL |= SysTick_CTRL_ENABLE;

    while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG) == 0)
    {
        /* code */
    }
    

    SysTick->CTRL &= ~SysTick_CTRL_ENABLE;

}

void Delay_ms(uint32_t ms)
{
    while (ms--)
    {
        Delay_us(1000);
    }
    
}

void Delay_s(uint32_t s)
{
    while (s--)
    {
        Delay_ms(1000);
    }
    
}
